import { IResponse } from '@/types/data'
import { IBannerItem, IGoodsHot, IGoodsNew } from '@/types/goods'
import request from '@/utils/request'
import { defineStore } from 'pinia'

export default defineStore('home', {
  state: () => ({
    // 轮播图数据
    bannerList: [] as IBannerItem[],
    // 新鲜好物数据
    newGoodsList: [] as IGoodsNew[],
    // 人气推荐
    hotGoodsList: [] as IGoodsHot[],
  }),
  actions: {
    async getBannerList() {
      const r = await request.get<IResponse<IBannerItem[]>>('/home/banner')
      this.bannerList = r.data.result
    },
    async getGoodsNewList() {
      const r = await request.get<IResponse<IGoodsNew[]>>('/home/new')
      this.newGoodsList = r.data.result
    },
    async getGoodsHotList() {
      const r = await request.get<IResponse<IGoodsHot[]>>('/home/hot')
      this.hotGoodsList = r.data.result
    },
  },
})
